﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CCS_Snake
{
    class LayoutEvent
    {
        public static void ThreadBtnGameControlsWidth(object parameter)
        {
            object[] __parameter = (object[])parameter;
            Form form = (Form)__parameter[0];
            Button button = (Button)__parameter[1];
            int startWidth = (int)__parameter[2];
            int endWidth = (int)__parameter[3];
            Button btnGameOver = (Button)__parameter[4];
            bool btnGameOverVisible = (bool)__parameter[5];

            if (startWidth > endWidth)
            {
                startWidth = -startWidth;
                endWidth = -endWidth;
            }

            if (!btnGameOverVisible) form.BeginInvoke(new Action(() => { btnGameOver.Visible = false; }));

            for (int index = startWidth; index <= endWidth; index += 10)
            {
                form.BeginInvoke(new Action(() => { button.Width = Math.Abs(index); }));
                Thread.Sleep(1);
            }

            if (btnGameOverVisible) form.BeginInvoke(new Action(() => { btnGameOver.Visible = true; }));            
        }
    }
}
